<?php


namespace app\office;


use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;

class Import
{
    
    /**
     * 导入季华实验室-科研成功
     * 这里的表格有两个位置空缺 D F
     * @param array $data
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     */
    public static function agentExamples($file)
    {
        $reader = IOFactory::createReader('Xlsx');
        $reader->setReadDataOnly(TRUE);
        $spreadsheet = $reader->load($file); //载入excel表格

        $worksheet = $spreadsheet->getActiveSheet();
        $highestRow = $worksheet->getHighestRow(); // 总行数
        $highestColumn = $worksheet->getHighestColumn(); // 总列数
        $highestColumnIndex = Coordinate::columnIndexFromString($highestColumn); // e.g. 5

        $lines = $highestRow - 1; 
        if ($lines <= 0) {
            return false;
        }

        $data = [];
        for ($row = 3; $row <= $highestRow; ++$row) {
            $data[$row-3]['title'] = trim($worksheet->getCellByColumnAndRow(2, $row)->getValue());
            $data[$row-3]['team_name'] = trim($worksheet->getCellByColumnAndRow(3, $row)->getValue());
            $data[$row-3]['people'] = trim($worksheet->getCellByColumnAndRow(5, $row)->getValue());
            $data[$row-3]['research_date'] = trim($worksheet->getCellByColumnAndRow(7, $row)->getValue());
            $data[$row-3]['technical'] = trim($worksheet->getCellByColumnAndRow(8, $row)->getValue());
            $data[$row-3]['stage'] = trim($worksheet->getCellByColumnAndRow(9, $row)->getValue());
            $data[$row-3]['content'] = trim($worksheet->getCellByColumnAndRow(10, $row)->getValue());
            $data[$row-3]['theoretical_level'] = trim($worksheet->getCellByColumnAndRow(11, $row)->getValue());
            $data[$row-3]['indicators'] = trim($worksheet->getCellByColumnAndRow(12, $row)->getValue());
            $data[$row-3]['innovation'] = trim($worksheet->getCellByColumnAndRow(13, $row)->getValue());
            $data[$row-3]['ownership'] = trim($worksheet->getCellByColumnAndRow(14, $row)->getValue());
            $data[$row-3]['maturity'] = trim($worksheet->getCellByColumnAndRow(15, $row)->getValue());
            $data[$row-3]['app_value'] = trim($worksheet->getCellByColumnAndRow(16, $row)->getValue());
            $data[$row-3]['prospect'] = trim($worksheet->getCellByColumnAndRow(17, $row)->getValue());
            $data[$row-3]['keyword'] = trim($worksheet->getCellByColumnAndRow(18, $row)->getValue());
            $data[$row-3]['collaborating'] = trim($worksheet->getCellByColumnAndRow(19, $row)->getValue());
            $data[$row-3]['remark'] = trim($worksheet->getCellByColumnAndRow(20, $row)->getValue());
            $data[$row-3]['status'] = trim($worksheet->getCellByColumnAndRow(21, $row)->getValue());
            $data[$row-3]['matching'] = trim($worksheet->getCellByColumnAndRow(22, $row)->getValue());

        }

        return $data;
        
    }

    /**
     * 导入公司名单
     */
    public static function company($file)
    {
        $reader = IOFactory::createReader('Xlsx');
        $reader->setReadDataOnly(TRUE);
        $spreadsheet = $reader->load($file); //载入excel表格

        $worksheet = $spreadsheet->getActiveSheet();
        $highestRow = $worksheet->getHighestRow(); // 总行数
        $highestColumn = $worksheet->getHighestColumn(); // 总列数
        $highestColumnIndex = Coordinate::columnIndexFromString($highestColumn); // e.g. 5

        $lines = $highestRow - 1; 
        if ($lines <= 0) {
            return false;
        }

        $data = [];
        for ($row = 2; $row <= $highestRow; ++$row) {
            $data[$row-2]['company'] = trim($worksheet->getCellByColumnAndRow(3, $row)->getValue());
            $data[$row-2]['address'] = trim($worksheet->getCellByColumnAndRow(5, $row)->getValue());
            $data[$row-2]['industry'] = trim($worksheet->getCellByColumnAndRow(9, $row)->getValue());
            $data[$row-2]['registered_address'] = trim($worksheet->getCellByColumnAndRow(7, $row)->getValue());
            $data[$row-2]['code'] = trim($worksheet->getCellByColumnAndRow(8, $row)->getValue());

        }

        return $data;
    }



    
}